package interview.demo;

/**
 * @Author tu zy
 * @Date 2020/12/8 15:48
 * @Version 1.0
 */
public class ThreadDemo4 {
    public static void main(String[] args) throws InterruptedException{
        Thread thread = new Thread(new Runnable() {
            @Override
            public void run(){
                int count =0;
                while (!Thread.currentThread().isInterrupted()&&count <1000){//isInterrupted方法返回为false
                    System.out.println("count="+count);
                    count++;
                    try {
                        Thread.sleep(100000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        });
        thread.start();
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        thread.interrupt();
    }

}
